import request from './axios'
import {DEFAULT_PAGENUM, DEFAULT_PAGESIZE} from "@/constent";

/**
 * 分页获取角色
 * @param pageNum
 * @param pageSize
 * @returns {AxiosPromise}
 */
export const getRoleList = (pageNum = DEFAULT_PAGENUM,pageSize = DEFAULT_PAGESIZE) => {
    return request({
        url:'/role/getRoleList',
        method:'get',
        params:{
            pageNum,
            pageSize
        }
    })
}

/**
 * 修改角色
 * @param data
 * @returns {Promise<AxiosResponse<any>>}
 */
export const updateRole = (data = {}) => {
    return request.post('/role/updateRole',data);
}

/**
 * 删除角色
 * @param roleId
 */
export const removeRole = (roleId) => {
    return request({
        url:'/role/removeRole',
        method:'get',
        params:{
            roleId
        }
    })
}

/**
 * 根据角色查菜单
 * @param roleId
 * @returns {AxiosPromise}
 */
export const getMenuIdsByRoleId = roleId => {
    return request({
        url:'/role/getMenuIdBuRoleId',
        method:'get',
        params:{
            roleId
        }
    })
}

/**
 * 给角色授权
 * @param data
 * @returns {Promise<AxiosResponse<any>>}
 */
export const saveMenuToRole = data => {
    return request.post('/role/savaMenuToRole',data);
}

/**
 * 获得所有可用角色信息
 * @returns {AxiosPromise}
 */
export const getRoleAvalList = () => {
    return request({
        url:'/role/getRoleAvalList',
        method:'get'
    })
}
